package com.baidu.structure.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.Surface;
import android.view.View;
import android.view.ViewGroup;

import com.baidu.structure.R;
import com.baidu.structure.adapter.vh.AddContactViewHolder;
import com.baidu.structure.bean.ContactBean;

import java.util.ArrayList;

/**
 * Created by sunmo on 2016/12/1.
 */
public class AddContactAdapter extends RecyclerView.Adapter<AddContactViewHolder> {
    private ArrayList<ContactBean> itemData;
    private LayoutInflater inflater;
    private OnAddClickListener mClickListener;

    public AddContactAdapter(ArrayList<ContactBean> itemData, Context context) {
        this.itemData = itemData;
        this.inflater = LayoutInflater.from(context);
    }

    @Override
    public AddContactViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = inflater.inflate(R.layout.adapter_contact, parent, false);
        return new AddContactViewHolder(v);
    }

    @Override
    public void onBindViewHolder(AddContactViewHolder holder, int position) {
        holder.getIconView().setImageResource(itemData.get(position).getIcon());
        holder.getTitleView().setText(itemData.get(position).getName());
        holder.getAddButton().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mClickListener.onAddClick((Integer) v.getTag());
            }
        });
        holder.getAddButton().setTag(position);
    }

    @Override
    public int getItemCount() {
        return itemData==null?0:itemData.size();
    }

    //add click
    public void setOnAddClickListener(OnAddClickListener clickListener){
        this.mClickListener=clickListener;
    }

    public interface OnAddClickListener {
        void onAddClick(int position);
    }
}
